package jiuxing

type StartInfo struct {
	Insulvoltage         uint16
	InsulResP            uint16
	InsulResN            uint16
	BrmVersion           []byte
	BrmBatType           byte
	BrmCap               byte
	BrmVoltage           uint16
	BrmBat               string
	BrmBatSn             []byte
	BrmBatBirth          string
	BrmChargeCnt         uint32
	BrmBatOwn            byte
	BrmVin               string
	BrmSoftVersion       []byte
	BcpSigleAllowVoltage uint16
	BcpMaxAllowCurrent   uint16
	BapCap               uint16
	BcpMaxVoltage        uint16
	BcpMaxAllowTemp      byte
	BcpSoc               uint16
	BcpBatVoltage        uint16
}

type Msg21 struct {
	Tm         []byte
	PlugIdx    uint8
	Order      string
	UserId     string
	UserType   uint16
	GroupCode  string
	CarId      string
	CtlMode    byte
	CtlParam   uint32
	ChargeMode byte
	PileType   byte
	Result     byte
	Reason     uint16
	StartTime  []byte
	StartPwr   uint32
	StartInfo  StartInfo
}

func (msg *Msg21) Decode(b []byte) {
	item := NewByteArray(b)
	msg.Tm = item.GetTimeArray(0)
	msg.PlugIdx = item.GetUint8(6)
	msg.Order = item.GbkString(7, 32)
	msg.UserId = item.GbkString(39, 32)
	msg.UserType = item.GetUint16(71)
	msg.GroupCode = item.GbkString(73, 9)
	msg.CarId = item.GbkString(82, 9)
	msg.CtlMode = item.GetUint8(8)
	msg.CtlParam = item.GetUint32(92)
	msg.ChargeMode = item.GetUint8(96)
	msg.PileType = item.GetUint8(97)
	msg.Result = item.GetUint8(98)
	msg.Reason = item.GetUint16(99)
	if msg.Result == 2 {
		return
	}
	msg.StartTime = item.ByteArray(101, 6)
	msg.StartPwr = item.GetUint32(107)

}
